//
//  GalleriesTableViewCell.m
//  ArtDog
//
//  Created by dllo on 16/9/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "GalleriesTableViewCell.h"
#import "BaseCollectionView.h"
#import "UIImageView+WebCache.h"
#import "GalleryVos.h"
#import "GalleryExhibits.h"
#import "HLMacro.h"
#import "ImageViewCollectionCell.h"
#import "ArtistMainModel.h"
#import "HomeExhibitWorkList.h"

@interface GalleriesTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *funsLabel;

@property (weak, nonatomic) IBOutlet UILabel *oneLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headPicImage;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *exhibitLabel;
@property (weak, nonatomic) IBOutlet UILabel *worksLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UIImageView *addImage;
@property (weak, nonatomic) IBOutlet BaseCollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@end

@implementation GalleriesTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [_collectionView registerNib:[UINib nibWithNibName:@"ImageViewCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"imageViewCollectionCell"];
    UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)_collectionView.collectionViewLayout;
    layout.itemSize = CGSizeMake(SCREEN_WIDTH / 3 - 8, SCREEN_WIDTH / 3 - 8);
    
}

- (void)setGalleryModel:(GalleryVos *)galleryModel
{
    _galleryModel = galleryModel;
    [_headPicImage sd_setImageWithURL:[NSURL URLWithString:galleryModel.galleryPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _nameLabel.text = galleryModel.galleryName;
    _exhibitLabel.text = [NSString stringWithFormat:@"%@", galleryModel.exhibitNum];
    _worksLabel.text = [NSString stringWithFormat:@"%@", galleryModel.workNum];
    _cityLabel.text = galleryModel.cityName;
    if (galleryModel.exhibits == nil || galleryModel.exhibits.count == 0) {
        _collectionView.hidden = YES;
        _lineView.hidden = NO;
    } else {
        _collectionView.hidden = NO;
        _lineView.hidden = YES;
    }
    [self collectionViewProcotol];
    [_collectionView reloadData];
    
}

- (void)setArtistModel:(ArtistMainModel *)artistModel
{
    _artistModel = artistModel;
    
    [_headPicImage sd_setImageWithURL:[NSURL URLWithString:artistModel.headPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _nameLabel.text = artistModel.userName;
    _exhibitLabel.text = [NSString stringWithFormat:@"%@", artistModel.worksNum];
    _funsLabel.text = @"粉丝：";
    _oneLabel.text = @"作品：";
    _worksLabel.text = [NSString stringWithFormat:@"%@", artistModel.fansNum];
    _cityLabel.hidden = YES;
    _cityWordLabel.hidden = YES;
    if (artistModel.workList == nil || artistModel.workList.count == 0) {
        _collectionView.hidden = YES;
        _lineView.hidden = NO;
    } else {
        _collectionView.hidden = NO;
        _lineView.hidden = YES;
    }
    [self collectionViewArtistProcotol];
    [_collectionView reloadData];
}

- (void)collectionViewArtistProcotol
{
    [_collectionView collectionViewWithNumberOfItems:^(UICollectionView * _Nonnull collectionView, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        collectionViewParam.numberOfItems =  _artistModel.workList.count;
    } andCellForItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        ImageViewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageViewCollectionCell" forIndexPath:indexPath];
        cell.urlImage = _artistModel.workList[indexPath.item].worksPic;
        collectionViewParam.returnCell = cell;
    } andDidSelectItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath) {
        
    }];

}

- (void)collectionViewProcotol
{
    [_collectionView collectionViewWithNumberOfItems:^(UICollectionView * _Nonnull collectionView, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        collectionViewParam.numberOfItems =  _galleryModel.exhibits.count;
    } andCellForItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        ImageViewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageViewCollectionCell" forIndexPath:indexPath];
        cell.urlImage = _galleryModel.exhibits[indexPath.item].exhibitPic;
        collectionViewParam.returnCell = cell;
    } andDidSelectItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath) {
        
    }];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
